package so.sao.code.service.domain.entity;

import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;

import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import lombok.Data;
import so.sao.code.service.infrastructure.enums.TAG_BATCH_TYPE;
import so.sao.code.service.infrastructure.jpa.convert.TagBatchTypeConvert;

/**
 * 批次二维码可用码段记录表
 *
 * @author wjwei
 */
@Entity
@Data
@EntityListeners(AuditingEntityListener.class)
public class TagBatchLookupTable extends BaseEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = 264220224247133686L;
	@NotNull
	private Long eseId;
	@NotNull
	private Long tagBatchId;
	/**
	 * 批次类型，参照so.sao.code.enums.TagBatchType
	 */
	@Convert(converter = TagBatchTypeConvert.class)
	private TAG_BATCH_TYPE type = TAG_BATCH_TYPE.NORMAL;

	/**
	 * 码段开始序号
	 */
	private Long seqnumStart = 0L;
	/**
	 * 码段结束序号
	 */
	private Long seqnumEnd = 0L;
	/**
	 * 当前已使用的标签数量
	 * <p>
	 * 该码段可用的条件为 seqnumStart + currentCount + count(想要生成的数量) <= seqnumEnd
	 */
	private Long currentCount = 0L;
	/**
	 * 当前版本号，用于实现乐观锁
	 */
	@Version
	private Integer version = 0;
}
